package zua.program.androidstudioprogram01;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class CheckActivity extends AppCompatActivity {
    Button btn_check,btn_back;
    TextView tv_check;
    String str = null;
    private final int MainToCheck = 520;
    private final int CheckToMain = 1314;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check);

        //将定义的值与其在xml中对应的id绑定
        btn_check = findViewById(R.id.button_check);
        btn_back = findViewById(R.id.button_back);
        tv_check = findViewById(R.id.textView_check);

        Intent intent1 = getIntent(); //首先要定义一个intent值
        str = intent1.getStringExtra("username");


        //设置监听器
        btn_check.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //Intent intent1 = getIntent(); //首先要定义一个intent值
                //intent1.getStringExtra("answer"); //拿到answer的值
                tv_check.setText(intent1.getStringExtra("answer")); //将answer的值显示出来
                Toast.makeText(CheckActivity.this, "小可爱，看了答案要记在心里，就像你永远在我心里一样", Toast.LENGTH_SHORT).show();
                setResult(CheckToMain);  //结果码
            }
        });
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent2 = getIntent();
                //int count = Integer.parseInt(intent2.getStringExtra("count"));
                // 跳转
                Intent intent3 = new Intent(CheckActivity.this,QuestionActivity.class);
                intent3.putExtra("count",intent2.getStringExtra("count"));
                intent3.putExtra("username",str);
                startActivity(intent3);   //启动
            }
        });
    }
}
